<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员身份管理</title>
</head>
<body>
    <div th:fragment="content">
        <div class="container-fluid">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2 class="h3">管理员身份管理</h2>
                <div>
                    <a href="/admin/add-admin-form" class="btn btn-primary">
                        <i class="fas fa-plus me-1"></i> 添加管理员
                    </a>
                </div>
            </div>

            <!-- 提示信息 -->
            <div class="alert alert-success mb-4" th:if="${successMessage != null}">
                <i class="fas fa-check-circle me-2"></i>
                <span th:text="${successMessage}">操作成功</span>
            </div>

            <div class="alert alert-danger mb-4" th:if="${errorMessage != null}">
                <i class="fas fa-exclamation-circle me-2"></i>
                <span th:text="${errorMessage}">操作失败</span>
            </div>

            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">管理员列表</h5>
                </div>
                <div class="card-body">
                    <div class="table-container">
                        <table class="data-table table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>电话</th>
                                    <th>邮箱</th>
                                    <th>状态</th>
                                    <th>创建时间</th>
                                    <th>最后登录</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="admin : ${admins}" th:if="${not #lists.isEmpty(admins)}">
                                    <td th:text="${admin.userId}">1</td>
                                    <td th:text="${admin.username}">admin</td>
                                    <td th:text="${admin.phone}">13812345678</td>
                                    <td th:text="${admin.email}">admin@example.com</td>
                                    <td>
                                        <span th:if="${admin.status == 'active'}" class="badge bg-success">正常</span>
                                        <span th:if="${admin.status == 'frozen'}" class="badge bg-danger">禁用</span>
                                    </td>
                                    <td th:text="${#temporals.format(admin.createdAt, 'yyyy-MM-dd HH:mm')}">2023-01-01 00:00</td>
                                    <td th:text="${admin.lastLogin != null ? #temporals.format(admin.lastLogin, 'yyyy-MM-dd HH:mm') : '从未登录'}">2023-06-22 10:30</td>
                                    <td>
                                        <a th:href="@{'/admin/edit-admin-form/' + ${admin.userId}}" class="btn btn-sm btn-primary me-1">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <a th:href="@{'/admin/delete-admin/' + ${admin.userId}}"
                                           class="btn btn-sm btn-danger"
                                           onclick="return confirm('确定要删除该管理员吗？此操作不可恢复。')">
                                            <i class="fas fa-trash"></i>
                                        </a>
                                    </td>
                                </tr>
                                <tr th:if="${#lists.isEmpty(admins)}">
                                    <td colspan="8" class="text-center">暂无管理员数据</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
